<template>
    <!-- 主页头部导航栏 -->
    <div class="topNavbar"> 
      <div class="logo" @click="refresh">
        <img src="../assets/images/logo.png" alt="">
      </div>
      <div class="btn_box" @click="login" v-if="isShow">
        登录
      </div>
      <div class="btn_box" @click="goDownload" v-else >
        下载App
      </div>
    </div>
    <!-- 搜索框 -->
    <div class="searchBox" @click="goSearch">
      <div class="searchBar">
        <img src="../assets/images/search.png" class="search_icon">
        <span class="search_text">搜索</span>
      </div>
    </div>
  </template>
  
  <script setup lang="ts">
 
  
  import { ref } from 'vue';
import { useRouter } from 'vue-router'

  const isShow = ref(true)
  const token = localStorage.getItem('xmtoken')
  console.log(token);
  

  const router = useRouter()
  const refresh = () => {
    window.location.reload(); // 刷新页面
  }

  if(token){
    isShow.value = false
  }
  const login = () => {
   router.push('/login')
  }

  const goDownload = () => {
    window.location.href="https://m.ximalaya.com/applink?"
  }

  const goSearch = () => {
    router.push('search')
  }
  </script>
  
  <style lang="less" scoped>
  .topNavbar{
    width:350.2px;
    height:50px;
    display: flex;
    justify-content:space-between;
    align-items: center;
    padding: 15px 15px 5px
  }
  .logo{
    width: 116px;
    height: 29px;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .btn_box{
    width: 88px;
    height: 30px;
    background-color: #FA2800;
    border-radius: 20px;
    color: #fff;
    font-size: 14px;
    text-align: center;
    line-height: 30px;
  }
  .searchBox{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 375.2px;
    height: 46px;
  }
  .searchBar{
      display: flex;

      align-items: center;
      width: 345.2px;
      height: 30px;
      background-color: rgb(239, 241, 244);
      border-radius: 20px;
    }
    .search_icon{
      width: 14px;
      height: 14px;
      margin-left: 10px;
    }
    .search_text{
      font-size: 12px;
      color: #ABABAB;
      margin-left: 10px;
    }
  </style>